<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
    <title>Sistema de Contabilidad</title>    
    <link rel="shortcut icon" href="image/favicon.ico" />
    <link rel="stylesheet" href="/media/css/style.css" type="text/css" media="screen" />
    <link href="/media/css/dropdown.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/media/css/default.css" media="screen" rel="stylesheet" type="text/css" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta http-equiv="content-language" content="en-gb" />
    <meta http-equiv="imagetoolbar" content="false" />
</head>
<TITLE>Agregar Egreso</TITLE>

<script type="text/javascript" src="/media/js/CalendarPopup.js"></script>
<script type="text/javascript">
        var proveedores = new Array;
        var cuentas = new Array;
        var id_cuentas = new Array;
        var cant_valores=0;
        var listasel=0;
        
        function toggle() {
         for(i=11;i<=50;i++){
             if( document.getElementById("hidethis"+i).style.display=='none' ){
              document.getElementById("hidethis"+i).style.display = '';
              
             }/*else{
              document.getElementById("hidethis"+i).style.display = 'none';
              
             }*/
            }
        }
        
        function inicializar(frm){
            var i=0;
            {% for ip in pro %}
                proveedores[i]="{{ip.ruc}}";
                i++;
            {% endfor %}
            i=0;
            {% for ip1 in con %}
                cuentas[i]="{{ip1.tipo_de_iva}}";
                id_cuentas[i] = "{{ip1.id}}";
                i++;
            {% endfor %}
            cant_valores = i;

        }
        function poner_ruc(num){
            if(num.selectedIndex != 0){
                if(num != ""){
                    document.getElementById('ruc').value=proveedores[num-1];
                }else{
                    document.getElementById('ruc').value="";
                }
                
            }
        }
        function ver_tipo(num, g10, g5, ex, iva){
            var b=0;
            var pos=0;
            for(i=0;i<cant_valores;i++){
                if(id_cuentas[i] == num){
                    pos = i;
                    break;
                }
            }
            //alert(num);
            if(num.selectedIndex != 0){
                if(num != ""){
                    if(cuentas[pos] == 'c'){
                        g10.disabled=true;
                        ex.disabled=true;
                        iva.disabled=false;
                        g5.disabled=false;
                        g10.value=0;
                        ex.value=0;
                        b=1;
                        listasel=1;
                        //g10.setAttribute('disabled','disabled');
                        //document.formu.g101.disabled = true;
                        
                    }else{
                        g10.disabled = false;
                        ex.disabled = false;
                    }
                    if(b==0){
                        if(cuentas[pos] == 'd'){
                            g5.disabled = true;
                            ex.disabled = true;
                            iva.disabled=false;
                            g10.disabled=false;
                            g5.value=0;
                            ex.value=0;
                            listasel=1;
                            b=1;
                        }else{
                            g5.disabled = false;
                            ex.disabled = false;
                        }
                    }
                    if(b==0){
                        if(cuentas[pos] == 'e'){
                            g10.disabled = true;
                            g5.disabled = true;
                            iva.disabled=true;
                            ex.disabled=false;
                            g10.value=0;
                            g5.value=0;
                            iva.value=0;
                            listasel=1;
                        }else{
                            g10.disabled = false;
                            g5.disabled = false;
                            iva.disabled=false;
                        }
                    }
                    
                    //alert(num);
                }else{
                    //alert(cuentas[num-1]);
                    g10.disabled = false;
                    ex.disabled = false;
                    g5.disabled = false;
                    listasel=0;
                    //document.getElementById('ruc').value="";
                }
                
            }
            //alert(listasel);
        }
        function validar(e) { // 1
            tecla = (document.all) ? e.keyCode : e.which;
            if (tecla==8) return true; //Tecla de retroceso (para poder borrar)
            if (tecla==0) return true;
            patron = /[1234567890.-]/;// Solo acepta numeros y el punto

            te = String.fromCharCode(tecla);
            return patron.test(te); 
        } 

        //alert('as');
        function sumval(frm, n, tipo_iva){
            //alert('as');
            var valor;
            var b=0;
            var pos=0;
            for(i=0;i<cant_valores;i++){
                if(id_cuentas[i] == tipo_iva){
                    pos = i;
                    break;
                }
            }
            if(frm['cant'+n].value!="" && frm['mon'+n].value!=""){
                
                valor = parseFloat(frm['cant'+n].value) * parseFloat(frm['mon'+n].value)
                valor = Math.round(valor * Math.pow(10, 2)) / Math.pow(10, 2);
                if(cuentas[pos] != "e" && cuentas[pos] != "n"){
                    frm['totiva'+n].value = valor;
                }else{
                    frm['ex'+n].value = valor
                }
                
            }else{
                frm['totiva'+n].value = 0;
                frm['g10'+n].value = 0;
                frm['g5'+n].value = 0;
                frm['ex'+n].value = 0;
            }
            if(listasel == 1){
                if(cuentas[pos] == "d"){
                    var div = parseFloat(frm['totiva'+n].value) / 1.1;
                    div = Math.round(div * Math.pow(10, 2)) / Math.pow(10, 2);
                    div = Math.round(div);
                    frm['g10'+n].value = div;
                    b=1;
                }else{
                    b=0;
                    frm['g10'+n].value = 0;
                }
                if(b==0){
                    if(cuentas[pos] == "c"){
                        var div = parseFloat(frm['totiva'+n].value) / 1.05;
                        div = Math.round(div * Math.pow(10, 2)) / Math.pow(10, 2);
                        div = Math.round(div);
                        frm['g5'+n].value = div;
                        b=1;
                    }else{
                        b=0;
                        frm['g5'+n].value = 0;
                    }
                }
                
                
            }
            
        }
        
        function sumar(frm){
            var sum=0;
            var uno=0;
            var sumtotiva=0;
            var sumg10=0;
            var sumg5=0;
            var sumex=0;
            var sumtotgral = 0
            for(i=1;i<=10;i++){
                if(parseInt(frm['cant'+i].value) > 0){
                    uno = uno + 1;
                }
                if(parseInt(frm['des'+i].value) > 0){
                    uno = uno + 1;
                }
                if(parseInt(frm['mon'+i].value) > 0){
                    uno = uno + 1;
                }
                
                if(uno>0 && uno<3){
                    alert("Verifique que los valores de la fila "+i+" esten completos (Cantidad, precio unitario, etc)");
                    uno = 0;
                    return false;
                }
                uno = 0;
            }
            
            for(i=1;i<=10;i++){
                if(frm['mon'+i].value == ''){
                    frm['mon'+i].value = 0;
                }
                if(frm['totiva'+i].value == ''){
                    frm['totiva'+i].value = 0;
                }
                if(frm['g10'+i].value == ''){
                    frm['g10'+i].value = 0;
                }
                if(frm['g5'+i].value == ''){
                    frm['g5'+i].value = 0;
                }
                if(frm['ex'+i].value == ''){
                    frm['ex'+i].value = 0;
                }
            }

            for(i=1;i<=10;i++){
                sumtotiva = sumtotiva + parseFloat(frm['totiva'+i].value);
                sumg10 = sumg10 + parseFloat(frm['g10'+i].value);
                sumg5 = sumg5 + parseFloat(frm['g5'+i].value)
                sumex = sumex + parseFloat(frm['ex'+i].value)
                sumtotgral = sumtotiva + sumex;
            }

            frm['totiva'].value= Math.round(sumtotiva * Math.pow(10, 2)) / Math.pow(10, 2);
            frm['totgv10'].value=Math.round(sumg10 * Math.pow(10, 2)) / Math.pow(10, 2);
            frm['totgv5'].value=Math.round(sumg5 * Math.pow(10, 2)) / Math.pow(10, 2);
            frm['totex'].value =Math.round(sumex * Math.pow(10, 2)) / Math.pow(10, 2);
            frm['totgral'].value = Math.round(sumtotgral * Math.pow(10, 2)) / Math.pow(10, 2);
            
            frm['totivah'].value = frm['totiva'].value;
            frm['totgv10h'].value = frm['totgv10'].value;
            frm['totgv5h'].value = frm['totgv5'].value;
            frm['totexh'].value = frm['totex'].value;
            frm['totgralh'].value = frm['totgral'].value;
            if(sumtotiva!=0 || sumg10!=0 || sumg5!=0 || sumex!=0){
                frm.boton.disabled = false;
            }
        }
         function ValidarFecha(Cadena){  
             var Fecha= new String(Cadena)   // Crea un string  
             var RealFecha= new Date()   // Para sacar la fecha de hoy  
             // Cadena Anho  
             var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))  
             // Cadena Mes  
             var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))  
             // Cadena Dia  
             var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))  

             /*var Dia= new String(Fecha.substring(Fecha.lastIndexOf("-")+1,Fecha.length))  
             var Mes= new String(Fecha.substring(Fecha.indexOf("-")+1,Fecha.lastIndexOf("-")))  
             var Ano= new String(Fecha.substring(0,Fecha.indexOf("-")))*/
           
             // Valido el anho  
             if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){  
                     alert('Fecha invalida')  
                 return false  
             }  
             // Valido el Mes  
             if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){  
                 alert('Mes invalido')  
                 return false  
             }  
             // Valido el Dia  
             if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){  
                 alert('Dia invalido')  
                 return false  
             }  
             if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {  
                 if (Mes==2 && Dia > 28 || Dia>30) {  
                     alert('Dia invalido')  
                     return false  
                 }  
             }  
               
           //para que envie los datos, quitar las  2 lineas siguientes  
           //alert("Fecha correcta.")  
           return true    
           
         }  
         function verificar(frm){
            if(frm['pro'].value == ""){
                //nopasa=1;
                //
                alert("Ingrese nombre de proveedor");
                return 0;
            }
            if(frm['date1xx'].value == ""){
                alert("Ingrese fecha del documento");
                return 0;
            }
             if(frm['tipodoc'].value == ""){
                //nopasa=1;
                //
                alert("Seleccione el tipo de documento");
                return 0;
            }
            if(frm['nrofac'].value == ""){
                alert("Ingrese numero del documento");
                return 0;
            }
            
            //frm['boton'].submit();
            //frm['formu'].submit();
            //alert(frm['tipodoc'].value);
            if(ValidarFecha(frm['date1xx'].value)){
                //frm['boton'].submit();
                //frm['formu'].submit();
                document.formu.submit();
            }
        }
         var cal1xx = new CalendarPopup("testdiv1");
            cal1xx.showNavigationDropdowns();
            document.write(getCalendarStyles());
            writeSource("jscal1xx");
        
</script>

<body onload="inicializar(this.form);">
    <div>
    <table align="center" border="0">
    <td align="left" width=11%><h3>Bienvenido<font color="#888"> {{nombreuser}}</font> </h3></td>
    </div>
    <td align="right" width=82%>
    <div id="header">
        <h1>Contabilidad</h1>
        <h2>Sistema Contable - Obispado</h2>
    </div></td>
    <tr>
    </TABLE>
    
    <ul id="nav" class="dropdown dropdown-horizontal">
        <li><a href="/obispado/logout/">Desconectarse</a></li>
        <li class="dir">Ingresos ▼
            <ul>
                <li><a href="/obispado/carga_ingresos/">Cargar Ingresos</a></li>
                <li><a href="/obispado/ingresos_list/">Ver Ingresos</a></li>
                <li><a href="/obispado/solicitar_planilla_ingresos/">Planilla Ingresos</a></li>
            </ul>
        </li>
        <li class="dir">Egresos ▼
            <ul>
                <li><a href="/obispado/carga_egresos/">Cargar Egresos</a></li>
                <li><a href="/obispado/egresos_list/">Ver Egresos</a></li>
                <li><a href="/obispado/solicitar_planilla_egresos/">Planilla Egresos</a></li>
            </ul>
        </li>
        <li class="dir">Asientos ▼
            <ul>
                <li><a href="/obispado/cargar_asiento/">Cargar Asientos</a></li>
                <li><a href="/obispado/asientos_list/">Ver Asientos</a></li>
            </ul>
        </li>

        <li><a href="/obispado/admin/aportantes/aportante/">Aportantes</a></li>
        <li><a href="/obispado/admin/proveedores/proveedor/">Proveedores</a></li>
        <li><a href="/obispado/balances/csv/">Generar Balance</a></li>
        <li class="dir">Administrar Sistema ▼
            <ul>
                <li><a href="/obispado/admin/">Administracion General</a></li>
                <li><a href="/obispado/registro/">Crear un nuevo usuario</a></li>
                <li><a href="/obispado/admin/password_change/">Cambiar Contrase&ntilde;a del usuario actual</a></li>
                <li><a href="/obispado/ver_logs">Ver logs</a></li>
            </ul>
        </li>
    </ul>
    <br></br>
    <div id="content" align="center">
        <h1>Editar Egreso</h1>
            {% if msj %}
            <table align="center" style="float:center;border:3px solid red;">
            <td align="center" width="500">{{msj}}</td>
            <tr>
            </TABLE>
            <br>
            {% endif %}
            
    
<FORM action="/obispado/egresos_update/" METHOD="GET" name="formu">
<table align="center" border="0">
<td align="left" width="100">Proveedor:
</td>
<!--td align="center" width="150"><INPUT NAME="pro" TYPE="TEXT" VALUE="">
</td-->
<td align="left" width="100">
                        
                            <select name="pro" id="id_pro" onchange="poner_ruc(this.value);">

                            <!--option value="" selected="selected">---------</option-->
                            {% if pro %}
                                {% for i in pro %}
                                    {% ifequal i.id idpro %}
                                        <option value="{{ i.id }}" selected="selected">{{ i.nombre }}</option>
                                    {% else %}
                                        <option value="{{ i.id }}">{{ i.nombre }}</option>
                                    {% endifequal %}
                                {% endfor %}
                            {% endif %}
                            <!--option value="d">Debe</option>
                            <option value="h">Haber</option>
                            <option value="h4">Fer</option-->
</select>
<!--td align="center" width="150"><INPUT NAME="ap" TYPE="TEXT" VALUE=""-->
</td>
<tr>
<td align="left" width="100">RUC/CI:
</td>
<td align="left" width="150"><INPUT NAME="ruc" id = "ruc" TYPE="TEXT" VALUE="{{ rucval }}" disabled="disabled">
</td>
<tr>
<td align="left" width="200">Fecha:
</td>
<!--td align="center" width="150"><INPUT NAME="fe" TYPE="TEXT" VALUE="" onChange = "ValidarFecha(this.value);">
<tr-->
<td align="left" width="200"><input name="date1xx" value="{{ feval }}" type="text"><a href="#" onclick="cal1xx.select(document.forms[0].date1xx,'anchor1xx','dd/MM/yyyy'); return false;" title="cal1xx.select(document.forms[0].date1xx,'anchor1xx','dd/MM/yyyy'); return false;" name="anchor1xx" id="anchor1xx">Elegir</a>
</td>
<tr>
<td align="left" width="100">Tipo de documento:
</td>
<td align="left" width="150"><select name="tipodoc" id="id_tipodoc">
    {% ifequal tipo_doc "Factura" %}
        <option value="" >---------</option>
        <option value="1" selected="selected">Factura</option>
        <option value="2">Recibo</option>
        <option value="3">Autofactura</option>
    {% endifequal %}
    {% ifequal tipo_doc "Recibo" %}
        <option value="" >---------</option>
        <option value="1">Factura</option>
        <option value="2" selected="selected">Recibo</option>
        <option value="3">Autofactura</option>
    {% endifequal %}
    {% ifequal tipo_doc "Autofactura" %}
        <option value="" >---------</option>
        <option value="1">Factura</option>
        <option value="2">Recibo</option>
        <option value="3" selected="selected">Autofactura</option>
    {% endifequal %}
</select>
</td>
<tr>
<td align="left" width="100">Nro Documento:
</td>
<td align="left" width="150"><INPUT NAME="nrofac" TYPE="TEXT" VALUE="{{nro_fact}}">
</td>
</TABLE>
<table align="center" border="0">
<tr>
<td align='left' width='20'>Cantidad:</td><td align='left' width='100'>Concepto:</td><td align='left' width='100'>Precio Unitario:</td><td align='left' width='80'>Total Iva Incluido:</td><td align='left' width='80'>Grav10%:</td><td align='left' width='80'>Grav5%:</td><td align='left' width='80'>Exentas:</td>
<tr>

{% for v in ltot %}
<td align='left' width='50'><INPUT NAME='cant{{forloop.counter}}' TYPE='TEXT' VALUE='1' size="10" onFocus = "sumval(this.form, '{{forloop.counter}}', this.form.des{{forloop.counter}}.value);" onChange = "sumval(this.form, '{{forloop.counter}}', this.form.des{{forloop.counter}}.value);" onkeypress="return validar(event);"></td>
<td align="left" width="100"><select name="des{{forloop.counter}}" id="id_des{{forloop.counter}}" onchange="ver_tipo(this.value, this.form.g10{{forloop.counter}}, this.form.g5{{forloop.counter}}, this.form.ex{{forloop.counter}}, this.form.totiva{{forloop.counter}});" onClick = "ver_tipo(this.value, this.form.g10{{forloop.counter}}, this.form.g5{{forloop.counter}}, this.form.ex{{forloop.counter}}, this.form.totiva{{forloop.counter}});" onMouseOver="ver_tipo(this.value, this.form.g10{{forloop.counter}}, this.form.g5{{forloop.counter}}, this.form.ex{{forloop.counter}}, this.form.totiva{{forloop.counter}});">

                            <option value="">---------</option>
                            {% if con %}
                                {% for i in con %}
                                    {% ifequal i.id v.cuenta %}
                                        <option value="{{ i.id }}" selected="selected">{{ i.nombre }}</option>
                                    {% else %}
                                        <option value="{{ i.id }}">{{ i.nombre }}</option>
                                    {% endifequal %}
                                {% endfor %}
                            {% endif %}
                            
</select>

</td>

<td align='left' width='50'><INPUT NAME='mon{{forloop.counter}}' TYPE='TEXT' VALUE='{{v.monto}}' size="10" onFocus = "sumval(this.form, '{{forloop.counter}}', this.form.des{{forloop.counter}}.value);" onChange = "sumval(this.form, '{{forloop.counter}}', this.form.des{{forloop.counter}}.value);" onkeypress="return validar(event);"></td>
{% if v.tipoiva == "d" %}
<td align='left' width='50'><INPUT NAME='totiva{{forloop.counter}}' TYPE='TEXT' VALUE='{{v.monto}}' size="10" onkeypress="return validar(event);"></td>
{% else %}{% if v.tipoiva == "c" %}
<td align='left' width='50'><INPUT NAME='totiva{{forloop.counter}}' TYPE='TEXT' VALUE='{{v.monto}}' size="10" onkeypress="return validar(event);"></td>
{% else %}
<td align='left' width='50'><INPUT NAME='totiva{{forloop.counter}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);"></td>
{% endif %}{% endif %}
<td align='left' width='50'><INPUT NAME='g10{{forloop.counter}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);"></td>
<td align='left' width='50'><INPUT NAME='g5{{forloop.counter}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);" ></td>
{% if v.tipoiva == "e"%}
<td align='left' width='50'><INPUT NAME='ex{{forloop.counter}}' TYPE='TEXT' VALUE='{{v.monto}}' size="10" onkeypress="return validar(event);" ></td>
{% else %}{% if v.tipoiva == "n" %}
<td align='left' width='50'><INPUT NAME='ex{{forloop.counter}}' TYPE='TEXT' VALUE='{{v.monto}}' size="10" onkeypress="return validar(event);" ></td>
{% else %}
<td align='left' width='50'><INPUT NAME='ex{{forloop.counter}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);" ></td>
{% endif %}{% endif %}
<tr>
{% endfor %}

{% if cantval < 10 %}
    {% for i in listf %}
     <td align='left' width='50'><INPUT NAME='cant{{i}}' TYPE='TEXT' VALUE='' size="10" onFocus = "sumval(this.form, '{{i}}', this.form.des{{i}}.value);" onChange = "sumval(this.form, '{{i}}', this.form.des{{i}}.value);" onkeypress="return validar(event);"></td>
    <td align="left" width="100"><select name="des{{i}}" id="id_des{{i}}" onchange="ver_tipo(this.value, this.form.g10{{i}}, this.form.g5{{i}}, this.form.ex{{i}}, this.form.totiva{{i}});" onClick = "sumval(this.form, '{{i}}', this.form.des{{i}}.value);" onMouseOver= "sumval(this.form, '{{i}}', this.form.des{{i}}.value);">

                                <option value="">---------</option>
                                {% if con %}
                                    {% for i in con %}
                                        {% ifequal i.id v.cuenta %}
                                            <option value="{{ i.id }}" selected="selected">{{ i.nombre }}</option>
                                        {% else %}
                                            <option value="{{ i.id }}">{{ i.nombre }}</option>
                                        {% endifequal %}
                                    {% endfor %}
                                {% endif %}
                                
    </select>
    
    </td>
    <td align='left' width='50'><INPUT NAME='mon{{i}}' TYPE='TEXT' VALUE='' size="10" onFocus = "sumval(this.form, '{{i}}', this.form.des{{i}}.value);" onChange = "sumval(this.form, '{{i}}', this.form.des{{i}}.value);" onkeypress="return validar(event);"></td>
    <td align='left' width='50'><INPUT NAME='totiva{{i}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);"></td>
    <td align='left' width='50'><INPUT NAME='g10{{i}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);"></td>
    <td align='left' width='50'><INPUT NAME='g5{{i}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);" ></td>
    <td align='left' width='50'><INPUT NAME='ex{{i}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);" ></td>
    <tr>
    
    {% endfor %}
{% endif %}


{% for i in listresto %}
    <tr id="hidethis{{i}}" style="display:none;">
     <td align='left' width='50'><INPUT NAME='cant{{i}}' TYPE='TEXT' VALUE='' size="10" onFocus = "sumval(this.form, '{{i}}', this.form.des{{i}}.value);" onChange = "sumval(this.form, '{{i}}', this.form.des{{i}}.value);" onkeypress="return validar(event);"></td>
    <td align="left" width="100"><select name="des{{i}}" id="id_des{{i}}" onchange="ver_tipo(this.value, this.form.g10{{i}}, this.form.g5{{i}}, this.form.ex{{i}}, this.form.totiva{{i}});" onClick = "sumval(this.form, '{{i}}', this.form.des{{i}}.value);" onMouseOver= "sumval(this.form, '{{i}}', this.form.des{{i}}.value);">

                                <option value="">---------</option>
                                {% if con %}
                                    {% for i in con %}
                                        {% ifequal i.id v.cuenta %}
                                            <option value="{{ i.id }}" selected="selected">{{ i.nombre }}</option>
                                        {% else %}
                                            <option value="{{ i.id }}">{{ i.nombre }}</option>
                                        {% endifequal %}
                                    {% endfor %}
                                {% endif %}
                                
    </select>
    
    </td>
    <td align='left' width='50'><INPUT NAME='mon{{i}}' TYPE='TEXT' VALUE='' size="10" onFocus = "sumval(this.form, '{{i}}', this.form.des{{i}}.value);" onChange = "sumval(this.form, '{{i}}', this.form.des{{i}}.value);" onkeypress="return validar(event);"></td>
    <td align='left' width='50'><INPUT NAME='totiva{{i}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);"></td>
    <td align='left' width='50'><INPUT NAME='g10{{i}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);"></td>
    <td align='left' width='50'><INPUT NAME='g5{{i}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);" ></td>
    <td align='left' width='50'><INPUT NAME='ex{{i}}' TYPE='TEXT' VALUE='' size="10" onkeypress="return validar(event);" ></td>
    </tr>
    
    {% endfor %}
<td align="left" width="100"><INPUT NAME="botonfilas" type="button" VALUE="Agregar mas filas" onClick="toggle();"><br /><br /></td>
    
<td align="left" width="100">Total:
</td>
<td align="left" width="100"></td>
<td align="left" width="100"></td>
<!--td align="left" width="100"><INPUT NAME="totmon" TYPE="TEXT" VALUE="" disabled="disabled" size="10">
</td-->
<td align="left" width="100"><INPUT NAME="totiva" TYPE="TEXT" VALUE="" disabled="disabled" size="10">
<input type="hidden" value="" name="totivah" />
</td>
<td align="left" width="100"><INPUT NAME="totgv10" TYPE="TEXT" VALUE="" disabled="disabled" size="10">
<input type="hidden" value="" name="totgv10h" />
</td>
<td align="left" width="100"><INPUT NAME="totgv5" TYPE="TEXT" VALUE="" disabled="disabled" size="10">
<input type="hidden" value="" name="totgv5h" />
</td>
<td align="left" width="100"><INPUT NAME="totex" TYPE="TEXT" VALUE="" disabled="disabled" size="10">
<input type="hidden" value="" name="totexh" />
</td>
<tr>
<td align="left" width="100">Total General:
</td>
<td align="left" width="100"><INPUT NAME="totgral" TYPE="TEXT" VALUE="" disabled="disabled" size="10">
<input type="hidden" value="" name="totgralh" />
</td>
<tr>

<tr>
<td align="center" width="150"></td>
<td align="center" width="150"><INPUT NAME="boton" type="button" VALUE="Enviar" disabled="disabled" onclick="verificar(this.form);">
</td>
<td align="center" width="150"><input name="botons" type="button" value="Sumar" onclick="sumar(this.form);" /></td>
<input type="hidden" value="{{nro}}" name="nro_mod" />
</TABLE>
<script type="text/javascript">
    var cuentas = new Array;
    var id_cuentas = new Array;
    var cant_valores=0;
    var i=0;
    var j=0;
    var pos=-1;
    var b=0;
    var listasel=0;
    {% for ip1 in con %}
        cuentas[i]="{{ip1.tipo_de_iva}}";
        id_cuentas[i] = "{{ip1.id}}";
        i++;
    {% endfor %}
    cant_valores = i;
    cant_editar = {{cantval}}
    for(i=1; i<=cant_editar;i++){
        for(j=0;j<cant_valores;j++){
            //alert(document.forms["formu"]['des'+i].value);
            if(document.forms["formu"]['des'+i].value == id_cuentas[j]){
                pos = j;
                break;
            }
        }
        if(pos != -1){
        //alert(cuentas[pos]);
            if(cuentas[pos] == 'c'){
                document.forms["formu"]['g10'+i].disabled=true;
                document.forms["formu"]['ex'+i].disabled=true;
                document.forms["formu"]['totiva'+i].disabled=false;
                document.forms["formu"]['g5'+i].disabled=false;
                document.forms["formu"]['g10'+i].value=0;
                document.forms["formu"]['ex'+i].value=0;
                b=1;
                listasel=1;
            }else{
                document.forms["formu"]['g10'+i].disabled = false;
                document.forms["formu"]['ex'+i].disabled = false;
            }
            if(b==0){
                if(cuentas[pos] == 'd'){
                    document.forms["formu"]['g5'+i].disabled = true;
                    document.forms["formu"]['ex'+i].disabled = true;
                    document.forms["formu"]['totiva'+i].disabled=false;
                    document.forms["formu"]['g10'+i].disabled=false;
                    document.forms["formu"]['g5'+i].value=0;
                    document.forms["formu"]['ex'+i].value=0;
                    b=1;
                    listasel=1;
                }else{
                    document.forms["formu"]['g5'+i].disabled = false;
                    document.forms["formu"]['ex'+i].disabled = false;
                }
            }if(b==0){
                if(cuentas[pos] == 'e'){
                    document.forms["formu"]['g10'+i].disabled = true;
                    document.forms["formu"]['g5'+i].disabled = true;
                    document.forms["formu"]['totiva'+i].disabled=true;
                    document.forms["formu"]['ex'+i].disabled=false;
                    document.forms["formu"]['g10'+i].value=0;
                    document.forms["formu"]['g5'+i].value=0;
                    document.forms["formu"]['totiva'+i].value=0;
                    listasel=1;
                }else{
                    document.forms["formu"]['g10'+i].disabled = false;
                    document.forms["formu"]['g5'+i].disabled = false;
                    document.forms["formu"]['totiva'+i].disabled=false;
                }
            }
            if(document.forms["formu"]['cant'+i].value!="" && document.forms["formu"]['mon'+i].value!=""){
                valor = parseFloat(document.forms["formu"]['cant'+i].value) * parseFloat(document.forms["formu"]['mon'+i].value)
                valor = Math.round(valor * Math.pow(10, 2)) / Math.pow(10, 2);
                if(cuentas[pos] != "e" && cuentas[pos] != "n"){
                    document.forms["formu"]['totiva'+i].value = valor;
                }else{
                    document.forms["formu"]['ex'+i].value = valor
                } 
            }else{
                document.forms["formu"]['totiva'+i].value = 0;
                document.forms["formu"]['g10'+i].value = 0;
                document.forms["formu"]['g5'+i].value = 0;
                document.forms["formu"]['ex'+i].value = 0;
            }
            if(listasel == 1){
                if(cuentas[pos] == "d"){
                    var div = parseFloat(document.forms["formu"]['totiva'+i].value) / 1.1;
                    div = Math.round(div * Math.pow(10, 2)) / Math.pow(10, 2);
                    div = Math.round(div);
                    document.forms["formu"]['g10'+i].value = div;
                    b=1;
                }else{
                    b=0;
                    document.forms["formu"]['g10'+i].value = 0;
                }
                if(b==0){
                    if(cuentas[pos] == "c"){
                        var div = parseFloat(document.forms["formu"]['totiva'+i].value) / 1.05;
                        div = Math.round(div * Math.pow(10, 2)) / Math.pow(10, 2);
                        div = Math.round(div);
                        document.forms["formu"]['g5'+i].value = div;
                        b=1;
                    }else{
                        b=0;
                        document.forms["formu"]['g5'+i].value = 0;
                    }
                }
            }
        }
        b=0;
        pos = -1;
    }

</script>
</FORM>
<DIV ID="testdiv1" STYLE="position:absolute;visibility:hidden;background-color:white;layer-background-color:white;"></DIV>
<tr>
</div>
</BODY>
</HTML>


